<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.41">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 113.0px; text-indent: -113.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 113.0px; text-indent: -113.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #000000; min-height: 14.0px}
p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #9d1c12}
p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000; min-height: 12.0px}
p.p13 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0000bf}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #3b68c1}
span.s3 {font: 12.0px Times}
span.s4 {text-decoration: underline}
span.s5 {font: 12.7px Helvetica}
span.s6 {color: #0000bf}
span.s7 {color: #000000}
span.s8 {color: #bf0000}
span.s9 {font: 9.0px Lucida Grande}
span.s10 {color: #606060}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>Dtag</b></span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><b>demand rate tag system</b></p>
<p class="p2"><br></p>
<p class="p1">superclass: DbufTag</p>
<p class="p2"><br></p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p1"><span class="Apple-tab-span">	</span><b>*new(bufsize, v, axiom, rules, recycle, mode)</b></p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p3"><span class="Apple-tab-span">	</span><b>bufsize</b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>maximum string size - when this size is reached, the process ends (dependent on <b>mode</b>).<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Theoretically, tag systems have an infinite "tape" (memory) size - practically, one may want to try different finite sizes. This value is static.</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>for a version that runs on a separate buffer, see [<a href="DbufTag.htm"><span class="s2">DbufTag</span></a>]</p>
<p class="p4"><br></p>
<p class="p3"><span class="Apple-tab-span">	</span><b>v</b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>deletion number (<span class="s3"><b><i>ν</i></b></span>). Number of symbols that are deleted at each step.</p>
<p class="p4"><span class="Apple-tab-span">	</span></p>
<p class="p3"><span class="Apple-tab-span">	</span><b>axiom</b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>the string to start with - use<b> integers from 0 to N</b>, which correspond to rule indices.</p>
<p class="p4"><span class="Apple-tab-span">	</span></p>
<p class="p3"><span class="Apple-tab-span">	</span><b>rules</b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>the production rules are given as an array of arrays.<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>for each integer the production rule at that <b>position</b> is chosen (see rule schema below).</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></p>
<p class="p3"><span class="Apple-tab-span">	</span><b>recycle</b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>if this is not zero, the tag system simply adds this value as an offset to its write position<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>and continues where it normally would end.<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>This results in a<b> recycling tag system</b> (see below).</p>
<p class="p4"><span class="Apple-tab-span">	</span></p>
<p class="p3"><span class="Apple-tab-span">	</span><b>mode</b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>this parameter decides in what case to apply the above recycle parameter.<span class="Apple-converted-space"> </span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>If recycle = 0, only mode 4 makes a difference.</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>mode 0: both recycle when string overrun or string empty (default case)</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>mode 1: recycle only when string overrun, halt when empty</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>mode 2: recycle only when string empty, halt when overrun</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>mode 3: always halt</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>mode 4: always halt and post information.</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>mode 5: same, but post buffer values (max 32) and rule number.</p>
<p class="p2"><br></p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p1">Most inputs, also rule values, may themselves be demand rate ugens, or any other ugen or value. Thus, while the rule sizes stay the same, the rule values may dynamically changed. If those values are demand rate ugens, the rule values and the deletion number are evaluated each cycle, recycle is called each time the system ends.</p>
<p class="p2"><br></p>
<p class="p1">At each step, Dtag outputs the<b> tagged symbol</b>, which is the rule index for the next step. If the appended string is needed instead, this can be done by applying the method <b>allSymbols</b> to the UGen.</p>
<p class="p2"><br></p>
<p class="p5">// rule schema</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>0 -&gt; 00</p>
<p class="p7"><span class="Apple-tab-span">	</span>1 -&gt; 1101</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>is written as [[0, 0], [1, 1, 0, 1]]</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>0 -&gt; 02</p>
<p class="p7"><span class="Apple-tab-span">	</span>1 -&gt; 1101</p>
<p class="p7"><span class="Apple-tab-span">	</span>2 -&gt; 01</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>is written as [[0, 2], [1, 1, 0, 1], [0, 1]]</p>
<p class="p8"><br></p>
<p class="p2"><br></p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p1"><b>Emil Post's tag systems</b></p>
<p class="p2"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></p>
<p class="p1">Emil Post developed tag systems from the 1920s onward as an instrument of generalization of symbolic logic, hoping that it would allow the study of properties like decidability and completeness. Due to their intractibility he gave up the attempt to prove their unsolvability. Minsky showed later that tag systems are recursively unsolvable, i.e. of equivalent to a universal turing machine [2].</p>
<p class="p2"><br></p>
<p class="p1">This type of rewriting system consists of an initial string of symbols (<b><i>axiom</i></b>), a set of rules and a deletion number (<span class="s3"><b><i>ν</i></b></span>). In our implementation, Post's parameter <b><i>μ</i></b> (size of the alphabet) is implicit is the number of letters in the alphabet used. The deletion number is a very interesting parameter, since it determines what part of the string forms the instructions for the process and what part is omitted. Post described three classes of behaviour: <i>termination</i>, <i>periodicity</i>, and <i>divergence</i>.<i> "The classes with μ = 1 or </i><span class="s3"><b><i>ν</i></b></span><i> = 1 or </i><span class="s3"><b><i>ν</i></b></span><i> = μ = 2 were proven solvable. The case with μ = 2, </i><span class="s3"><b><i>ν</i></b></span><i> &gt; 2 he calls intractable, while he terms the cases μ &gt; 2, </i><span class="s3"><b><i>ν</i></b></span><i> = 2 as being of 'bewildering complexity'"</i> [4].</p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p1"><b>Further reading</b><span class="Apple-converted-space"> </span></p>
<p class="p2"><br></p>
<p class="p1">[1] Martin Davis, <i>The undecidable. Basic papers on undecidable propositions, unsolvable problems and computable functions</i>, New York 1965. (see "Account of an anticipation”).</p>
<p class="p1">[2] Marvin Minsky. <i>Recursive unsolvability of post’s problem of tag and other topics in the theory of turing machines.</i> Annals of Mathematics, 74:437–455, 1961.</p>
<p class="p1">[3] Elizabeth de Mol, <i>Tracing Unsolvability. A Mathematical, Historical and Philosophical analysis with a special focus on tag systems. </i><span class="s4">http://logica.ugent.be/centrum/writings/doctoraten.php</span>. (thanks a lot for introducing me to this topic!)</p>
<p class="p1">[4] Elizabeth de Mol, Closing the circle: An analysis of emil post’s early work., The Bulletin of Symbolic Logic 12.</p>
<p class="p1">[5] Emil Post, <i>Formal reductions of the combinatorial decision problem</i>, American Journal of Mathematics, 65 (2), 197-215 (1943). (see p.203ff.)</p>
<p class="p2"><br></p>
<p class="p1">More poetically, looking out for complex messages hidden in noise: Stanisłav Lem, <i>His Master's Voice</i>, 1968<span class="s5">.</span></p>
<p class="p2"><br></p>
<p class="p2"><br></p>
<p class="p1"><b>How it works</b></p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p1">In the beginning, the string is the axiom, and its first symbol is tagged.<span class="Apple-converted-space"> </span></p>
<p class="p1">At each step, the rule is looked up that corresponds to this tagged symbol: 1 corresponds to the rule with index 1 (the 2nd), 0 corresponds to the rule with index 0 (the 1st) etc.</p>
<p class="p2"><br></p>
<p class="p1">If no rule is found, the process halts. Otherwise, two things happen:<span class="Apple-converted-space"> </span></p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s3"><b><i>ν</i></b></span> number of symbols are dropped from the string by moving the tag <span class="s3"><b><i>ν </i></b></span>steps forward,<span class="Apple-converted-space"> </span></p>
<p class="p1"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>At the other end of the string, the symbols of the corresponding production rule are appended.</p>
<p class="p2"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></p>
<p class="p1">When the string is empty (i.e. the tag has reached its rightmost end), or the maximum memory size is reached, the process halts. When you set mode to 4, this information is posted (be careful, because posting at very high frequencies can overload the system).</p>
<p class="p2"><br></p>
<p class="p9"><br></p>
<p class="p5">// One of the examples by Emil Post</p>
<p class="p5">// printout: "|" represents the tag, "&gt;" represents the end of the string.</p>
<p class="p5">// the printout is limited to 32 characters</p>
<p class="p7">(</p>
<p class="p7">{ </p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> tag, trig;</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span>trig = </span><span class="s6">Impulse</span><span class="s7">.kr(2); </span>// advance 2 times a second</p>
<p class="p7"><span class="Apple-tab-span">	</span>tag = <span class="s6">Dtag</span>(</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>2048, </span>// maximum string size</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>3, </span>// advance three steps each turn</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>[1, 0, 1], <span class="s8">// axiom</span></p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>[[1, 0], [1, 1, 0, 1]], <span class="s8">// rules</span></p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>0, </span>// no recycle</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>5 </span>// print mode</p>
<p class="p7"><span class="Apple-tab-span">	</span>);</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">Demand</span>.kr(trig, 0, tag);</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span>0.0 </span>// silence for now</p>
<p class="p7">}.play;</p>
<p class="p7">)</p>
<p class="p9"><br></p>
<p class="p2"><br></p>
<p class="p1"><b>Recycling tag systems: a variant of tag systems</b></p>
<p class="p2"><br></p>
<p class="p1">Like in an early procedure by Emil Post, in this implementation the symbols are not deleted from the end, but the reading position is advanced (the tag is moved forward). Mathew Cook developed a variant, where instead of a single axiom, one has a list of axioms that is used one after the other [3].</p>
<p class="p2"><br></p>
<p class="p1">Instead of assuming an infinite tape or such an axiom list, one now can try and see what happens if one assumes a <b>cyclic tape</b> instead - while this may not add any expressive power to the concept, it is an interesting special case. At the loop point (a certain limit string size), <b>a new axiom is chosen from the beginning (r &gt; 0), or backward, from the end of the tape (r &lt; 0).</b></p>
<p class="p2"><br></p>
<p class="p1">If <b>recycle is not 0</b>, instead of halting, the old string is reused by cutting out an axiom of that length from the current position and the process continues. For <b>r &gt; 0</b> the read position is advanced by r steps, for <b>r &lt; 0</b> the tag is moved back by r steps.</p>
<p class="p1">If <b>mode = 1</b>, recycling happens only when the string is too large.<span class="Apple-converted-space"> </span></p>
<p class="p1">If <b>mode = 2</b>, recycling happens happens only when the string is empty. (see above)</p>
<p class="p8"><br></p>
<p class="p10">// example:<span class="Apple-converted-space"> </span></p>
<p class="p11">0 1 0|0 1 1 (vertical line is the tag. with r= 2, the new axiom would be 01, v= -3 it would be 010)</p>
<p class="p2"><br></p>
<p class="p1">In the metaphor of the tag game, the recycle parameter (<b>r</b>) is the head start for the runaway writer before the tagger (see: <span class="s4">http://en.wikipedia.org/wiki/Tag_%28game%29</span>)</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p2"><br></p>
<p class="p8"><br></p>
<p class="p8"><br></p>
<p class="p1"><b>Examples</b></p>
<p class="p8"><br></p>
<p class="p6"><br></p>
<p class="p7">s.boot;</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p5">// the examples by Emil Post again</p>
<p class="p5">// directly listen to the tag system output (audification)</p>
<p class="p5">// when the string size exceeds the size, the synth is freed (doneAction: 2)</p>
<p class="p7">(</p>
<p class="p7">{ </p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> tag, axiom, rules, size, dt;</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span>dt = </span><span class="s6">SampleDur</span><span class="s7">.ir; </span>// play with audio rate</p>
<p class="p7"><span class="Apple-tab-span">	</span>size = <span class="s6">SampleRate</span>.ir * 2;</p>
<p class="p7"><span class="Apple-tab-span">	</span>axiom = [1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1];</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span></span>// axiom = axiom.scramble.keep(rrand(4, 16)).postln;</p>
<p class="p7"><span class="Apple-tab-span">	</span>v = 3;</p>
<p class="p7"><span class="Apple-tab-span">	</span>rules = [[1, 0], [1, 1, 0, 1]];</p>
<p class="p7"><span class="Apple-tab-span">	</span>tag = <span class="s6">Dtag</span>(size, v, axiom, rules);</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">TDuty</span>.ar(dt, 0, tag, doneAction: 2).dup * 0.1</p>
<p class="p7">}.play;</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p5">// the above as a frequency input for a sine oscillator</p>
<p class="p5">// control delta time by cursor position</p>
<p class="p7">(</p>
<p class="p7">{ </p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> tag, axiom, rules, size, dt, sineFreq;</p>
<p class="p7"><span class="Apple-tab-span">	</span>dt = <span class="s6">MouseX</span>.kr(1e-1, 1e-4, 1);<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="Apple-tab-span">	</span>size = 48000 * 2;</p>
<p class="p7"><span class="Apple-tab-span">	</span>axiom = [1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1];</p>
<p class="p7"><span class="Apple-tab-span">	</span>v = 3;</p>
<p class="p7"><span class="Apple-tab-span">	</span>rules = [[1, 0], [1, 1, 0, 1]];</p>
<p class="p7"><span class="Apple-tab-span">	</span>tag = <span class="s6">Dtag</span>(size, v, axiom, rules);</p>
<p class="p7"><span class="Apple-tab-span">	</span>sineFreq = <span class="s6">Duty</span>.ar(dt, 0, tag, doneAction: 2)</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>* 200 + 300;</p>
<p class="p7"><span class="Apple-tab-span">	</span>(<span class="s6">SinOsc</span>.ar(sineFreq.lag(dt)) * <span class="s6">AmpCompA</span>.kr(sineFreq) * 0.2).dup</p>
<p class="p7">}.play;</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p5">// a slow demonstration</p>
<p class="p5">// see DbufTag for an output of the string itself</p>
<p class="p7">(</p>
<p class="p7">{ </p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> tag, index, trig, rules, axiom;</p>
<p class="p7"><span class="Apple-tab-span">	</span>axiom = [1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1];</p>
<p class="p7"><span class="Apple-tab-span">	</span>rules = [[0, 0], [1, 1, 0, 1]];</p>
<p class="p7"><span class="Apple-tab-span">	</span>trig = <span class="s6">Impulse</span>.kr(4);</p>
<p class="p7"><span class="Apple-tab-span">	</span>tag = <span class="s6">Dtag</span>(256, 2, axiom, rules, mode: 5);</p>
<p class="p7"><span class="Apple-tab-span">	</span>index = <span class="s6">Demand</span>.kr(trig, 0, tag).poll(trig);</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">SinOsc</span>.ar(index* 100 + 300 + <span class="s6">SinOsc</span>.kr([4, 4.1], 0, 8)) * 0.1</p>
<p class="p7">}.play;</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p5">/*</p>
<p class="p5">1 0 1 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 0 1</p>
<p class="p5"><span class="Apple-converted-space">    </span>1 0 1 0 0 1 1 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1</p>
<p class="p5"><span class="Apple-converted-space">        </span>1 0 0 1 1 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1</p>
<p class="p5"><span class="Apple-converted-space">            </span>0 1 1 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1</p>
<p class="p5"><span class="Apple-converted-space">                </span>1 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0</p>
<p class="p5"><span class="Apple-converted-space">                    </span>0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1</p>
<p class="p5"><span class="Apple-converted-space">                        </span>0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0</p>
<p class="p5"><span class="Apple-converted-space">                          </span>1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 0 0 0</p>
<p class="p5"><span class="Apple-converted-space">                              </span>1 1 0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 0 0 0 1 1 0 1</p>
<p class="p5"><span class="Apple-converted-space">                    <span class="Apple-tab-span">	</span></span>...</p>
<p class="p12"><span class="Apple-converted-space">                    </span></p>
<p class="p12"><span class="Apple-converted-space">              </span></p>
<p class="p5">creating the series: 1 1 1 0 1 0 0 1 1 ... <span class="Apple-converted-space">                                 </span></p>
<p class="p5">*/</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p5">// demonstrating the mechanism of a recycling tag system</p>
<p class="p5">// the tag game round the house</p>
<p class="p7">(</p>
<p class="p7">{ </p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> tag, trig;</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> deletionNumber = 3;</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> axiom = [0, 1, 2];</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> rules = [[0, 1], [2, 0], [1, 1]];</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span></span><span class="s6">var</span><span class="s7"> recycle = -3; </span>// head start when writer was tagged.</p>
<p class="p7"><span class="Apple-tab-span">	</span>tag = <span class="s6">Dtag</span>(9, deletionNumber, axiom, rules, recycle, 5);</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p13"><span class="s7"><span class="Apple-tab-span">	</span></span>SinOsc<span class="s7">.ar(</span></p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s6">Duty</span>.kr(1, 0, tag, doneAction:2)</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>* 100 + 300 + <span class="s6">SinOsc</span>.kr([4, 4.1], 0, 8)</p>
<p class="p7"><span class="Apple-tab-span">	</span>)<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="Apple-tab-span">	</span>* 0.1 ! 2</p>
<p class="p7">}.play;</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p5">// a more complicated tag system whith a random axiom.</p>
<p class="p5">// <span class="s9">μ</span> = 4</p>
<p class="p5">// v varies [1..6] with cursor position</p>
<p class="p5">// reinitialised when ended, a 1 sec pause each overrun.</p>
<p class="p7">(</p>
<p class="p7">{</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> tag, index, axiom, rules, freq, size;</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> deletionNumber = <span class="s6">MouseX</span>.kr(1, 6);</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></span>// this is a big buffer, which is expensive to alloc in real time.</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></span>// for large buffers, you may want to use DbufTag.</p>
<p class="p7"><span class="Apple-tab-span">	</span>size = 48000 * 4;<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="Apple-tab-span">	</span>freq = 15000;</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>axiom = <span class="s6">Array</span>.fill(14, { #[0, 1, 2, 3].choose });</p>
<p class="p7"><span class="Apple-tab-span">	</span>axiom.join(<span class="s10">" "</span>).postln;</p>
<p class="p7"><span class="Apple-tab-span">	</span>rules = [[0, 1, 1], [1, 3, 2, 0], [1, 2], [3, 1, 1]];</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>tag = <span class="s6">Dtag</span>(size, deletionNumber, axiom, rules, 0, mode: 4);</p>
<p class="p7"><span class="Apple-tab-span">	</span>tag = <span class="s6">Dseq</span>([tag, <span class="s6">Dseq</span>([0], freq)], <span class="s6">inf</span>);<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="Apple-tab-span">	</span>index = <span class="s6">Duty</span>.ar(1 / freq, 0, tag, doneAction:2);</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">SinOsc</span>.ar(index * 1200 + 400).dup * 0.1</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7">}.play;</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p5">// aliens calling</p>
<p class="p5">// <span class="s9">μ</span> = 4, recycling tag system.</p>
<p class="p5">// v varies (1..16) (cursor horizontal)</p>
<p class="p5">// varying recycle value (cursor vertical)</p>
<p class="p7">(</p>
<p class="p7">{ </p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> tag, index, axiom, rules, freq, size;</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> deletionNumber = <span class="s6">MouseX</span>.kr(1, 16).floor;</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">var</span> recycle = <span class="s6">MouseY</span>.kr(-60, 60).floor;</p>
<p class="p7"><span class="Apple-tab-span">	</span>recycle = recycle + (recycle.abs &lt; 1); <span class="s8">// avoid 0.</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>freq = <span class="s6">SampleRate</span>.ir;</p>
<p class="p5"><span class="s7"><span class="Apple-tab-span">	</span>size = 6000; </span>// small max string size. increase for higher complexity</p>
<p class="p7"><span class="Apple-tab-span">	</span>axiom = <span class="s6">Array</span>.fill(14, { #[0, 1, 2, 3].choose });</p>
<p class="p7"><span class="Apple-tab-span">	</span>axiom.join(<span class="s10">" "</span>).postln;</p>
<p class="p7"><span class="Apple-tab-span">	</span>deletionNumber.poll(label: <span class="s10">"deletionNumber"</span>);</p>
<p class="p7"><span class="Apple-tab-span">	</span>recycle.poll(label: <span class="s10">"recycle"</span>);</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>rules = [[0, 1, 1], [1, 3, 2, 0], [1, 2], [3, 1, 1]];</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7"><span class="Apple-tab-span">	</span>tag = <span class="s6">Dtag</span>(size, deletionNumber, axiom, rules, recycle);</p>
<p class="p7"><span class="Apple-tab-span">	</span>index = <span class="s6">Duty</span>.ar(1 / freq, 0, tag, doneAction:2);</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s6">SinOsc</span>.ar(index * 1200 + 400).dup * 0.1</p>
<p class="p6"><span class="Apple-tab-span">	</span></p>
<p class="p7">}.play;</p>
<p class="p7">)</p>
</body>
</html>
